package com.diana.config;

import com.diana.filter.BodyReaderFilter;
import com.diana.filter.MainFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class FilterConfig {

	@Autowired
	private MainFilter mainFilter;
	@Autowired
	private BodyReaderFilter bodyReaderFilter;

	@Bean
	public FilterRegistrationBean MyFilter() {
		FilterRegistrationBean registration = new FilterRegistrationBean();
		// 注入过滤器
		registration.setFilter(mainFilter);
		// 拦截规则
		registration.addUrlPatterns("/*");
		// 过滤器名称
		registration.setName("MainFilter");
		// 是否自动注册 false 取消Filter的自动注册
		registration.setEnabled(true);
		// 过滤器顺序
		registration.setOrder(Integer.MAX_VALUE - 100);
		return registration;
	}

	@Bean
	public FilterRegistrationBean<BodyReaderFilter> ReaderFilter() {
		FilterRegistrationBean registration = new FilterRegistrationBean();
		// 注入过滤器
		registration.setFilter(bodyReaderFilter);
		// 拦截规则
		registration.addUrlPatterns("/*");
		// 过滤器名称
		registration.setName("BodyReaderFilter");
		// 是否自动注册 false 取消Filter的自动注册
		registration.setEnabled(true);
		// 过滤器顺序
		registration.setOrder(Integer.MAX_VALUE - 101);
		return registration;
	}

}
